# -*- coding: UTF-8 -*-
"""
Debugger 服务器错误报告记录器
By AnpyD
"""

import sys
import traceback
from datetime import datetime

PATH = r"log.txt" # 日志文件路径


def Hook(tp, val, tb):
    LOG_FILE = open(PATH, "a")
    traceList = traceback.format_tb(tb)
    error = repr(tp) + "\n"
    error += (repr(val) + "\n")
    for line in traceList:
        error += (line + "\n")
    print >> LOG_FILE, datetime.now()
    print >> LOG_FILE, sys.stderr
    print >> LOG_FILE, error
    LOG_FILE.close()

sys.excepthook = Hook
